package com.smarttiger.zero.admin.dao;

import com.smarttiger.zero.admin.entity.SubscribeModel;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface SubscribeDao extends BaseDao<SubscribeModel> {

    public List<SubscribeModel> findByUsersIdAndMessageId(String userId,String messageId);

    @Modifying
    @Query("delete from SubscribeModel s where s.messageId = ?1")
    public void deleteByMessageId(String id);

    @Query("select s from SubscribeModel s left join MessageModel m on s.messageId = m.id where m.code = ?1")
    public List<SubscribeModel> findAllByMessageCode(String code);

    public List<SubscribeModel> findAllByMessageIdOrderByCreateDate(String mId);
}
